********************************
***Polarization Scenarios***
********************************

clear all

********************
*Set Person Working*
*Change this to your name!!!!!
********************
*global carolina 0
*global emily 1

global emily 1
global carolina 0

*********************
*Load Files*
*********************

*Carolina's Computer*
if $carolina ==1  {
cap cd "~\Dropbox\Carolina-Emily-Project\Data\Study"
global out "..\..\Results\"
}


if $emily ==1  {
*Emily's Computer*
cap cd "~/Dropbox/SourceContent/Data/Study"
global out "../../Results/"
} 

use 3_clean_data, replace

/*
*******************
Base Polarization Scenarios:
Own Leader:
1. With Prior - Total:  (5, Republican) & (2, Democrat) & 0
2. With Prior - Anonymous Message:  (7, Republican) & (4, Democrat) & 0
3. With Prior - Persuasion:  (7 & 5, Republican) & (4 & 2, Democrat)
4. Against Prior - Total:  (1, Republican) & (6, Democrat) & 0
5. Against Prior - Anonymous Message:  (3, Republican) & (8, Democrat) & 0
6. Against Prior - Persuasion:  (3 & 1, Republican) & (8 & 6, Democrat)

Opposition Leader: 
1. With Prior - Total:  (6, Republican) & (1, Democrat) & 0
2. With Prior - Anonymous Message:  (8, Republican) & (3, Democrat) & 0
3. With Prior - Persuasion:  (8 & 6, Republican) & (3 & 1, Democrat)
4. Against Prior - Total:  (2, Republican) & (5, Democrat) & 0
5. Against Prior - Anonymous Message:  (4, Republican) & (7, Democrat) & 0
6. Against Prior - Persuasion:  (4 & 2, Republican) & (7 & 5, Democrat)

Outcome is always anti

Structure: 
		& 		 & Polarization Change &  Control Mean
Message & Source & Control & \beta & (S.E.)  & \%Diff. & Republican & Democrat & N 
Party vs. Not & Leader vs. Opposition
*/

gen trump=treat==1 | treat==3 | treat==5 | treat==7 | treat==9
gen obama=trump==0 & treat>0
gen ownleader=trump if recruit==0
replace ownleader=obama if recruit==1
gen oppleader=1-ownleader
replace ownleader=1 if treat==0
replace oppleader=1 if treat==0

gen anti=treat>4 & treat<9
gen pro=treat>0 & treat<5
gen withprior=anti if recruit==0
replace withprior=pro if recruit==1
gen againstprior=1-withprior
replace withprior=1 if treat==0 | treat==9 | treat==10
replace againstprior=1 if treat==0 | treat==9 | treat==10

*4 Scenarios/Groups*
*1: With Prior, Own Leader
gen group1=ownleader==1 & withprior==1
*2: With Prior, Opposing Leader
gen group2=oppleader==1 & withprior==1
*3: Against Prior, Own Leader 
gen group3=ownleader==1 & againstprior==1
*4: Against Prior, Opposing Leader 
gen group4=oppleader==1 & againstprior==1

gen repub=recruit==0

gen president=treatment==1 | treatment==2 | treatment==5 | treatment==6
gen actor=treatment==3 | treatment==4 | treatment==7 | treatment==8
gen turkey= treatment==9 | treatment==10
gen priming=turkey==1 | president==1
gen message=actor==1 | president==1

/*
*For Total Effect*
ln(p(anti)+1)=b0+b1*republican+b2*president+b3*republican*president 
b3 is total change in polarization
*For Decomposition Effect*
ln(p(anti)+1)=0+b1*republican+b2*message+b3*president 
	+b4*republican*message+b5*republican*president
b4 is anonymous message change in polarization
b5 is persuasion change in polarization
*/

gen repub_president=repub*president
gen repub_message=repub*message
gen repub_priming=repub*priming

*********************************
***MAIN SCENARIOS***
*********************************

*********************************
***Create Variables and Format***
*********************************
	
global lasso0 hispanic age55_64 candidate16_hillary candidate16_other ///
	immlevel_decrease gun_lessstrict abortion_illegal tax_toohigh health_notgvt ///
	occ_twitter occ_buzzfeed trumpfan lebronfan taylorfan bgatesfan ///
	obamafan obama_neutral topissue_health 
	
global lasso1 black hispanic age35_44 age45_54 hsdegree ///
	candidate16_hillary immlevel_decrease immlevel_same ///
	gun_same gun_lessstrict abortion_partlegal abortion_illegal tax_toohigh ///
	health_neutral health_notgvt i.freq_nytimes ///
	daily_tv occ_tv daily_newspaper i.freq_fox week_breitbart ///
	daily_breitbart occ_buzzfeed ///
	lebron_neutral obamafan trump_neutral trumpfan west topissue_tax 
	

global message1 "Message With Prior"
global message2 "Message With Prior"
global message3 "Message Against Prior"
global message4 "Message Against Prior"
global leader1 "Own Leader"
global leader2 "Opposing Leader"
global leader3 "Own Leader"
global leader4 "Opposing Leader"

global effect1 "Total"
global effect2 "Anonymous Message"
global effect3 "Persuasion"
global effect4 "Total"
global effect5 "Anonymous Message"
global effect6 "Persuasion"

global dir0 "anti"
global dir1 "pro"


foreach y in 1 2 4 5 {
	global space`y' "[.2em]" 
	} 
foreach y in 3 {
	global space`y' "[1em]" 
	} 
foreach y in 6 {
	global space`y' "[1em]" 
	} 

*****************************
*****************************
*****************************

****************************************
*MAIN SCENARIO TABLE*
****************************************


preserve

file close _all
capture macro drop fh
file open fh using "${out}A1_Polarization_MessageFixed_VarySource.tex", write replace
file write fh ///
"\hspace*{-1cm}\small{\begin{tabular}{llcccc}"  _n 
	
file write fh ///
"\toprule" _n ///
" & & \multicolumn{3}{c}{\textbf{Polarization Change}}    \\ " ///
" & &  \multicolumn{3}{c}{\textit{ln(Probability Anti)}}  \\" ///
" & & \multicolumn{3}{c}{\textit{Change Diff.: Republican-Democrat}} \\ " ///
" \textbf{Leader} & \textbf{Effect} & $\beta$ &  (S.E.) & \%Diff. &  N \\" _n 


foreach y in 1 2 3 4 {

if `y'==1 | `y'==3 {

file write fh ///
"\midrule"  _n  ///
"\multicolumn{2}{l}{\textit{${message`y'}}} & & &    \\" _n ///
"[0.25em]" _n

}

reg ln1_prob_index_anti repub president repub_president $lasso0 $lasso1 ///
	if group`y'==1 & turkey==0 & actor==0

	local bt = round(_b[repub_president]*1000)/1000
	local bt : di %6.3f `bt'
	local st = round(_se[repub_president]*1000)/1000
	local st : di  %6.3f `st'
	count if e(sample)
	local nt = r(N)
	sum prob_index_anti if treat==0 & repub==1 & e(sample)==1
	local rt = r(mean)
	sum prob_index_anti if treat==0 & repub==0 & e(sample)==1
	local dt = r(mean)
	local mt = `rt'-`dt'
	local ct = (_b[president]+_b[repub_president])*(`rt'+1)-_b[president]*(`dt'+1)
	local ct = round(`ct'/`mt'*10000)/100
	local ct : di  %6.2f `ct'
	local pt = 2*ttail(e(df_r),abs(_b[repub_president]/_se[repub_president]))
	if `pt'<=0.1 & `pt'>0.05 {
		global start "*"
		}
	if `pt'<=0.05 & `pt'>0.01 {
		global start "**"
		}
	if `pt'<=0.01 {
		global start "***"
		}
	else if `pt'>0.1 {
		global start ""
		}

reg ln1_prob_index_anti repub president repub_president ///
	message repub_message $lasso0 $lasso1 ///
	if group`y'==1 & turkey==0

	count if e(sample)
	local n = r(N)

	local bm = round(_b[repub_message]*1000)/1000
	local bm : di %6.3f `bm'
	local sm = round(_se[repub_message]*1000)/1000
	local sm : di  %6.3f `sm'
	count if e(sample)
	sum prob_index_anti if treat==0 & repub==1 & e(sample)==1
	local rm = r(mean)
	sum prob_index_anti if treat==0 & repub==0 & e(sample)==1
	local dm = r(mean)
	local mm = `rm'-`dm'
	local cm = (_b[message]+_b[repub_message])*(`rm'+1)-(_b[message])*(`dm'+1)
	local cm = round(`cm'/`mm'*10000)/100
	local cm : di  %6.2f `cm'
	local pm = 2*ttail(e(df_r),abs(_b[repub_message]/_se[repub_message]))
	if `pm'<=0.1 & `pt'>0.05 {
		global starm "*"
		}
	if `pm'<=0.05 & `pt'>0.01 {
		global starm "**"
		}
	if `pm'<=0.01 {
		global starm "***"
		}
	else if `pm'>0.1 {
		global starm ""
		}		
		
	local bms = round(_b[repub_president]*1000)/1000
	local bms : di %6.3f `bms'
	local sms = round(_se[repub_president]*1000)/1000
	local sms : di  %6.3f `sms'
	count if e(sample)
	sum prob_index_anti if treat==0 & repub==1 & e(sample)==1
	local rms = r(mean)
	sum prob_index_anti if treat==0 & repub==0 & e(sample)==1
	local dms = r(mean)
	local mms = `rms'-`dms'
	local cms = (_b[president]+_b[repub_president])*(`rms'+1)-(_b[president])*(`dms'+1)
	local cms = round(`cms'/`mms'*10000)/100
	local cms : di  %6.2f `cms'
	local pms = 2*ttail(e(df_r),abs(_b[repub_president]/_se[repub_president]))
	if `pms'<=0.1 & `pt'>0.05 {
		global starms "*"
		}
	if `pms'<=0.05 & `pt'>0.01 {
		global starms "**"
		}
	if `pms'<=0.01 {
		global starms "***"
		}
	else if `pms'>0.1 {
		global starms ""
		}		
		
file write fh ///
	"${leader`y'} & Total & `bt'$start & (`st')  & `ct'\% & `nt' \\" _n ///
	"${leader`y'} & Anonymous Message & `bm'$starm & (`sm')  & `cm'\% & \\" _n ///
	"${leader`y'} & Source Persuasion & `bms'$starms & (`sms')  & `cms'\% & `n' \\" _n ///
	"[1em]" _n		
}

file write fh ///
"\bottomrule" _n ///
"\end{tabular}}\hspace*{-1cm}" _n
file close fh

restore



